<script type="text/javascript">
function mysqlTimeStampToDate(timestamp) 
{
    var regex = /^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
    var parts = timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
    return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
}
$(function () {
    $(".hiddenId").each(function(){
        var id = $(this).val();
        var endDate = $("#endtime_" + id).val();
        $('#defaultCountdown_'+id).countdown({until: mysqlTimeStampToDate(endDate)}); 
    });
});
</script>
<?php
$rows = 5;
$cols = 2;

$sql = "Select * From mid_products";
$result = @mysql_query($sql, $conn);
$total = countRecord("mid_products", "status = 0");
if($total == 0){
    echo "Hiện chưa có sản phẩm nào";
}
else {
    while($row = mysql_fetch_assoc($result)){
?>
    <table>
        <tr>
            <td><input type="hidden" class="hiddenId" id="id_<?php echo $row['id'] ?>" value="<?php echo $row['id'] ?>" /></td>
        </tr>
        <tr>
            <td><?php echo $row['product_name']?></td>
        </tr>
        <tr>
            <td id="<?php echo "defaultCountdown_" . $row['id'] ?>"></td>
        </tr>
        <tr>
            <td><input type="hidden" id="<?php echo "endtime_" . $row['id']?>" value="<?php echo $row['end_time'] ?>" /></td>
        </tr>
        <tr>
            <td>Giá bán: <?php echo number_format($row['price'],0,',','.')?> VNĐ</td>
        </tr>
    </table>
<?php
    }
}
?>
